package pool.tablename;


import java.util.Date;
import java.sql.ResultSet;
//import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Map;
import java.util.Vector;

import property.Sequence;

//import pool.preprocess.Preprocess;
import logger.ProcessLogger;
import utility.ConvertToLower;

//import utility.MessageGenerator;
import utility.ReplacesSpecialCharacter;
//import basicprocess.Basicprocess;

import database.Generatejoin;
import database.RecordSearch;
import dbmanager.ChekInMaster;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;


/**
 * @author Divyesh, 
 * @author Property_details class which is used for storing the word or property or entry into the Property_details.
 * And which will extends the SubPool class.
 * */
public class Property_details extends SubPool
{
	
	public Hashtable<Object,Object> BasicPropertyMap = new Hashtable<Object, Object>();
	
	/** PropertyMap which stores the the object of property_details. */
	public Hashtable<Object,Object> PropertyMap = new Hashtable<Object, Object>();
	/** Stores master reference for directly entry for property_details table. */
	public Hashtable<Object,Object> MasterMap = new Hashtable<Object, Object>();

	/** Vector for storing number of property_details object for multiple properties.*/
	Vector<Object> PropertyList =  new Vector<Object>(); 	

	private Vector<Object> OldPropertyVector = new Vector<Object>();
	private Vector<Object> NewPropertyVector = new Vector<Object>();	
	private String FROMDATE = "fd";
	private String TODATE = "td";
	/** Stores property_details table name.*/
	private String tableName = "property_details";	
	
	/** It will stores the Id for specific Name from master_table.*/
	private String TYPE="type";  
	/** It will stores the master Id for the reference, while inserting in to the property_details*/
	String mid;
	//private Basicprocess basicprocess;
	public Hashtable<Object,Object> MHash = new Hashtable<Object,Object>();
	/**Default constructor of property_details class.*/
	
	public Hashtable<Object,Object> ViewHashtable = new Hashtable<Object, Object>();	
	
	public boolean boolPdSetCommit = true;
	
	public Property_details(){}
	
	public Property_details(DBManager sqlDB)
	{
		this.sqlDB = sqlDB;
		gin = new GetIdName(sqlDB);
	}
	
	/**
	 * Property_details() constructor takes the following parameters,
	 * @param request which is table name for which the request is coming, either master_table or property_details.
	 * @param tableName which stores property_details as a table name.
	 * @param sqlDB stores the DBManager object.
	 * @param process which stores the type of process whether Add, Mod, etc.   
	 * */
	public Property_details(String request,String msg,String tableName,DBManager sqlDB,String process,String username)
	{
		message = msg;		
		this.tableName = tableName;
		this.sqlDB= sqlDB;
		this.Request = request;
		this.process = process;
		this.username = username;
		gin = new GetIdName(sqlDB);
		//TYPE = gin.getId("type");
		System.out.println("pool::PropertyDetails::Message in property : "+msg);
	}	
	
	
	/** The getInsert() will insert the properties into the property_details table.
	 *  @return sbrDTB StringBuffer which store the insertion message for the logger class.
	 * */
	@SuppressWarnings("unchecked")
	public StringBuffer getInsert() 
	{
		boolean eventResult = false;
		TYPE=gin.getId(TYPE);
		/*Vector<Object> vt = getProperties();
		ObjectDetection od=new ObjectDetection(sqlDB);
		od.checkRequestType(vt)*/
		 MasterMap.put("id", mid);
		try 
		{
			if(Request.toLowerCase().equals(tableName))
			{
				Hashtable<Object, Object>temperrorhashtable= process();
				if(temperrorhashtable.containsKey("ErrorInput"))
					return new StringBuffer((temperrorhashtable.get("ErrorInput")).toString());
			}	
		}
		catch (Exception e) 
		{
			//e.printStackTrace();
		}
		
		ReplacesSpecialCharacter replace = new ReplacesSpecialCharacter(sqlDB);		
		ChekInMaster check = new ChekInMaster(sqlDB);
		
		/*---------------------------------------------------------------------*/
		/*code for default property property  a*/
		
		if(!mid.equals("0"))
		{
			System.out.println("You are in pool::PropertyDetails ::getInsert():: ");			
			
			for(int p=0;p<PropertyList.size();p++)
			{
				Hashtable<Object,Object> tempProperty = new Hashtable<Object,Object>();
				
				
				tempProperty.putAll((Hashtable<Object, Object>)PropertyList.get(p));
				tempProperty.put("mid",mid);
				
				System.out.println("pool::PropertyDetails ::getInsert():: The Property Detail : " + tempProperty);
				System.out.println("pool::PropertyDetails ::getInsert():: The table name : " + tableName);
				tempProperty.put(TODATE, "null");
				if(check.isInProperty_details(tempProperty,tableName) == false)
				{						
					String pattern = "yyyy-MM-dd HH:MM:ss";
					SimpleDateFormat sdm = new SimpleDateFormat(pattern);
					String date = sdm.format(new Date());
					tempProperty.put(FROMDATE, date);
					int i = sqlDB.getInsert(tableName, tempProperty);
					if(i>0)
					{		
						System.out.println("\nretail::PropertyDetails ::getInsert():: Inserted Property in " + tableName + " .........\n\n" );
						//tempProperty = gin.convertMasterName(tempProperty, tableName, process);
						Hashtable<Object, Object> tempHash = new Hashtable<Object, Object>();
						tempHash.putAll(tempProperty);
						tempHash = GetIdName.removeno$(tempHash);
						//sbrDTB.append(replace.ReplacesChar("Following property is added : ", tempHash,"add"));
						sbrDTB.append("Following property is added : "+tempHash);
						strID = mid;	
						flagResult = true;
						eventResult = true;
					}
					else
					{	
						sbrDTB.append(" pool::PropertyDetails ::getInsert():: Unable to insert into Property Details ");
						System.out.println("pool::PropertyDetails ::getInsert():: Unable to insert into Property Details\n\n");
					
						flagResult = false;
					}
					
					
					if(flagResult == true)
						continue;
					else
						break;
				}
				else
				{
					sbrDTB.append(" pool::PropertyDetails ::getInsert():: Property Already exist ");
					System.out.println("pool::PropertyDetails ::getInsert():: Property Already exist ");
				
					flagResult = false;
				
				}
			}
			System.out.println("Eventprocess started..............");
			if(eventResult)
			{
				if(reqParam.getEvent())
				{			
					String type=getType();
					flagResult = addMasterToprocessLogger(this.mid, process, username,type,productName);
					System.out.println("Eventprocess completed..............");
				}
				else
					flagResult = false;
				//setVector(oldVector,basicReportVector);
				//Request = tableName;
				//getReport();
			}
			setReportMaster("add");
		}
		else
		{
			sbrDTB.append("pool::PropertyDetails ::getInsert():: Unable to insert into Property Details, Because of master entry does not exist...... ");
			System.out.println("pool::PropertyDetails ::getInsert():: Unable to insert into Property Details, Because of master entry does not exist...... ");
		
			flagResult = false;		
		}				
		
		boolPdSetCommit = flagResult;
		
		System.out.println(sbrDTB);
		return sbrDTB.append("\n ");
	}
	
	
	@SuppressWarnings("unchecked")
	public StringBuffer getUpdate() 
	{
		 TYPE=gin.getId(TYPE);
		 PropertyList.clear();
		 PropertyList.addAll(OldPropertyVector);
		 try 
			{
				if(Request.toLowerCase().equals(tableName))
				{
/*					Hashtable<Object, Object>temperrorhashtable= process();
					if(temperrorhashtable.containsKey("ErrorInput"))
						return new StringBuffer((temperrorhashtable.get("ErrorInput")).toString());*/
				}	
			}
			catch (Exception e) 
			{
				//e.printStackTrace();
			}
		//OldPropertyVector.clear();
		//OldPropertyVector.addAll(PropertyList);
		PropertyList.clear();
		 PropertyList.addAll(NewPropertyVector);
		// NewPropertyVector.clear();
		 try 
			{
				if(Request.toLowerCase().equals(tableName))
				{
					Hashtable<Object, Object>temperrorhashtable= process();
					if(temperrorhashtable.containsKey("ErrorInput"))
						return new StringBuffer((temperrorhashtable.get("ErrorInput")).toString());
				}	
			}
			catch (Exception e) 
			{
				//e.printStackTrace();
			}
		//NewPropertyVector.addAll(PropertyList);
		//PropertyList.clear();
		Hashtable<Object,Object> oldProperty = new Hashtable<Object, Object>();
		Hashtable<Object,Object> newProperty = new Hashtable<Object, Object>();
		try
		{
			
			for(int i = 0; i < NewPropertyVector.size();i++ )
			{
				
				try
				{
					newProperty.putAll( (Map<? extends Object, ? extends Object>) NewPropertyVector.get(i));
					//newProperty = temppd.PropertyMap;
					oldProperty = getOldPropertyHash(newProperty);
										
					//oldProperty = (Hashtable<Object, Object>)OldPropertyVector.get(i);
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}				
				
				try 
				{				
					Hashtable<Object, Object> tempProperty = new Hashtable<Object, Object>();
					tempProperty = sqlDB.getSelectCheck(oldProperty,tableName);
				
					if(tempProperty.isEmpty()||tempProperty.containsKey("Error"))
					{
						sbrDTB.append("Property not found or specify old property"+gin.convertMasterName(oldProperty,tableName,process).toString());
						System.out.println("pool::MasterClass::getUpdate():: " + sbrDTB);
						flagResult = false;
						continue;
					//	return sbrDTB;
					}
					oldProperty.putAll(ConvertToLower.convertHashKey(tempProperty));
					if(!oldProperty.containsKey(TODATE))
						oldProperty.put(TODATE, "null");
				}
				catch (Exception e) 
				{
					System.out.println("pool::MasterClass::getUpdate():: Exception ");
				}
				
				mid = newProperty.get("mid").toString();
			
				newProperty.put(TODATE, "null");
				if((oldProperty.get("mid").equals(newProperty.get("mid"))))
				{
					if((oldProperty.get("pid").equals(newProperty.get("pid"))))
					{
						if(newProperty.get("pv").equals("0")==true && newProperty.get("vt").equals("no$")==true)
						{
							sbrDTB.append(" pool::PropertyDetails ::getUpdate():: Please insert valid property with $NewPropertyname:Value|OldPropertyname:Value$NewPropertyname:Value|OldPropertyname:Value ");
							System.out.println("pool::PropertyDetails ::getUpdate():: Please insert valid property with $NewPropertyname:Value|OldPropertyname:Value$NewPropertyname:Value|OldPropertyname:Value \n\n");
							flagResult = false;
						}
						else
						{
							if(oldProperty.get("pv").equals("0")==true && oldProperty.get("vt").equals("no$")==true)
							{																
								sbrDTB.append(" pool::PropertyDetails ::getUpdate():: Please insert valid property with $NewPropertyname:Value|OldPropertyname:Value$NewPropertyname:Value|OldPropertyname:Value ");
								System.out.println("pool::PropertyDetails ::getUpdate():: Please insert valid property with $NewPropertyname:Value|OldPropertyname:Value$NewPropertyname:Value|OldPropertyname:Value \n\n");
								flagResult = false;
							}	
							else
							{
								ChekInMaster check = new ChekInMaster(sqlDB);
								if(check.isInProperty_details(newProperty,tableName)== false && check.isInProperty_details(oldProperty,tableName)==true)
								{
									if(oldProperty.get("td").equals("null"))
										oldProperty = sqlDB.getSelectCheck("select mid, pid, pv, vt,fd, ref from property_details where mid = '" + mid + "' and pid = '" + oldProperty.get("pid").toString() + "' and pv = '" + oldProperty.get("pv").toString() + "' and vt = '" + oldProperty.get("vt").toString() + "' and td is "+ oldProperty.get("td").toString()  );
									else
										oldProperty = sqlDB.getSelectCheck("select mid, pid, pv, vt,fd, ref from property_details where mid = '" + mid + "' and pid = '" + oldProperty.get("pid").toString() + "' and pv = '" + oldProperty.get("pv").toString() + "' and vt = '" + oldProperty.get("vt").toString() + "' and td='"+ oldProperty.get("td").toString() +"'" );
									String pattern = "yyyy-MM-dd HH:MM:ss";
									SimpleDateFormat sdm = new SimpleDateFormat(pattern);
									String date = sdm.format(new Date());
									
									Hashtable<Object,Object> tempoldProperty = new Hashtable<Object,Object>();
									tempoldProperty.put(TODATE, date);
									
									sqlDB.getUpdate(tableName,tempoldProperty,oldProperty);
									newProperty.put(FROMDATE, date);
									newProperty.put(TODATE, "null");
									
									int j = sqlDB.getInsert(tableName,newProperty);
									if(j>0)
									{
										System.out.println("pool::MasterClass::getUpdate():: Updated Success fully........");
										sbrDTB.append(" Following property is Updated..."+ newProperty.toString());	
										
										strID = mid;
										flagResult = true;
										eventResult = true;	
									}										
									else
									{
										System.out.println("pool::MasterClass::getUpdate():: Unable to Update........");
										sbrDTB.append(" Unable to Update ");
										flagResult = false;
									}
									
									if(flagResult == true)
										continue;
									else
										break;
								}
								else
								{
									System.out.println("pool::MasterClass::getUpdate():: Unable to Update. ");
									sbrDTB.append("Unable to Update. .");
									flagResult = false;
								}
							}						
						}
					}
					else
					{
						System.out.println("pool::MasterClass::getUpdate():: Unable to Update , Because entry for \"" + "pid" + "\" does not exists into the master_table ");
						sbrDTB.append("pool::MasterClass::getUpdate():: Unable to Update , Because entry for \"" + "pid" + "\" does not exists into the master_table ");
						flagResult = false;
					}
				}
				else
				{
					System.out.println("pool::MasterClass::getUpdate():: Unable to Update , Because entry for \"" + "mid" + "\" does not exists into the master_table ");
					sbrDTB.append("pool::MasterClass::getUpdate():: Unable to Update , Because entry for \"" + "mid" + "\" does not exists into the master_table ");
					flagResult = false;
				}
			}
			if(eventResult)
			{
				if(reqParam.getEvent())
				{
					String type=getType();
					flagResult = addMasterToprocessLogger(this.mid, process, username,type,productName);
				}
				else
					flagResult = false;
				//setVector(oldVector,basicReportVector);
				//Request = tableName;
				//getReport();
			}
		}
		catch (Exception e) 
		{
			System.out.println("pool::MasterClass::getUpdate():: Exception while creating a property. ");
			e.printStackTrace();
		}	
		
		//setReportMaster("add");
		System.out.println(sbrDTB);
		return sbrDTB;

	}

	
	@SuppressWarnings("unchecked")
	public StringBuffer getView() 
	{
		 TYPE=gin.getId(TYPE);
		 String masterTable = "master_table"; 
		StringBuffer sbrProperty=new StringBuffer();
		try {
			mid = gin.getId(MHash.get("name").toString());
		} catch (Exception e1) {
			mid ="no$";
		} 
		String mastermsg="";
							
		/*Hashtable<Object, Object> propertyHash= new Hashtable<Object, Object>();	
	  	propertyHash.putAll(ViewHashtable);
		
				if(propertyHash.get("pv").toString()=="0")
				{
					propertyHash.remove("pv");
				}
				Enumeration< Object> enum1 = propertyHash.keys();
				if(enum1.hasMoreElements()==false)
				{
						sbrProperty.append("Enter condition to view the properties");
						return sbrProperty;
				}
				if(propertyHash.size()==1)
				{
					if(propertyHash.containsKey("pid"))
					{
						sbrProperty.append("plz Enter the value of property ");
						return sbrProperty;					
					}
				}
				propertyHash.put(TODATE, "null");*/
				//According to the propertyHash getSelectVector method checks the condition ,searches all the record
				//through databse or in property_details table and stores into the vrs vector.
				
			Vector<Object> Condition = new Vector<Object>();
			Vector<Object> Field=new Vector<Object>();
			Vector<Object> Fieldlist=new Vector<Object>();
			Fieldlist.add("mid");
			Fieldlist.add("pid");
			Fieldlist.add("pv");
			Fieldlist.add("vt");
			for(int i=0;i<PropertyList.size();i++)
			{
				Property_details temppd=  (Property_details) PropertyList.get(i);
				String pv= temppd.PropertyMap.get("pv").toString();
				String vt= temppd.PropertyMap.get("vt").toString();
				
				if(pv.equals("0") && vt.equals("no$"))
					Field.add(temppd.PropertyMap);
				else
				{
					temppd.PropertyMap.put("conditionoperator","=");
					if(!mid.equals("no$"))
						temppd.PropertyMap.put("mid",mid);
					Condition.add(temppd.PropertyMap);
				}	
			}
			for(int i=0;i<Condition.size()-1;i++)
			{
				Hashtable<Object,Object> table = (Hashtable<Object, Object>) Condition.get(i);
				table.put("logicaloperator", "and");
				
			}
			
			Generatejoin gj = new Generatejoin();
			gj.setDatabase(sqlDB);
			gj.setTableName(tableName,Condition,"mid");
			String Query=gj.getResult(Fieldlist);
			if(Query.length()==0)
				Query = "SELECT * FROM "+tableName+" p_2 WHERE MID='"+mid+"' ";
			if(Field.size()>0)
				Query  = Query + "and (";
			
			for(int i=0;i<Field.size();i++)
			{
				Hashtable<Object, Object> table = (Hashtable<Object, Object>) Field.get(i);
				Enumeration<Object> enume = table.keys();
				while(enume.hasMoreElements())
				{
					String key = enume.nextElement().toString();
					String value = table.get(key).toString();
					if(!value.equals("0") && !value.equals("no$"))
						Query = Query + "p_2." + key +"="+ value + " or ";
				}
			}
			if(Field.size()>0)
				Query = Query.substring(0, Query.length()-3) + ")";
			ResultSet rs = sqlDB.getSelect(Query);
			Hashtable<Object, Object> property = new Hashtable<Object, Object>();
			try {
				while(rs.next())
				{
					String key = gin.getItem(rs.getString("pid"));
					String value = rs.getString("pv");
					if(value.equals("0"))
						value = rs.getString("vt");
					else
						value = gin.getItem(value);
					property.put(key, value);
				}
			}
			catch (Exception e) 
			{
				e.printStackTrace();
			}
			
			Sequence sequence = new Sequence();
			sequence.setDbmanager(sqlDB);
			String reponses=sequence.getReponses(reqParam.getKeyword(), property);
			property.clear();
			String value=gin.getId(reqParam.getKeyword());
			property.put("mid", value);
			property.put("pid", gin.getId("event"));
			RecordSearch recordsearch =new RecordSearch(sqlDB);
			recordsearch.setConditionMap(property);
			String line[]=recordsearch.getArrayFromResultSet();
			Hashtable<Object, Object> event =new Hashtable<Object, Object>();
			event.put("username", reqParam.getUsername());
			event.put("process", reqParam.getProcess());
			event.put("data", reponses);
			event.put("status", "0");
			
			for(int i=0;i<line.length;i++)
			{
				String splitline[] = line[i].split("\t");
				event.put("masterobject", value);
				sqlDB.getInsert("eventprocess", event);
			}
			Vector<Object> vrs  = new Vector<Object>(); 
				//	vrs.addAll(sqlDB.getSelectVector(propertyHash, tableName));
			
				String presentproperties="";
				String lastMid="";
				
				//For the wrong input to the trans_property_details request it shows empty records.
				
//				if(vrs.isEmpty())
//				{
//					sbrProperty.append("Record is not avilable");
//					return sbrProperty;
//				}
				/*
				for(int i=0;i<vrs.size();i++)
				{
					String presentproperty="";
					String Master=" ";
					Hashtable<Object, Object> hashobj=new Hashtable<Object, Object>();
					Hashtable<Object, Object> MasterObj=new Hashtable<Object, Object>();
					hashobj=(Hashtable<Object, Object>) vrs.get(i);
					hashobj.putAll(ConvertToLower.convertHashKey(hashobj));						
					
					if(hashobj.containsKey("fd"))
					{							
						if(hashobj.get("fd").toString().equals(""))
						{
							hashobj.remove("fd");
						}
					}
					
					if(hashobj.containsKey("td"))
					{
						if(hashobj.get("td").toString().equals(""))
						{
							hashobj.remove("td");
						}
					}
					hashobj.putAll(gin.CheckFromMaster(hashobj,process));
					
					MasterObj.put("name", hashobj.get("mid"));
					MHash=getMasterMap();						
					
					//MHash is set from the master table which contain an name of master only if the request is for  transaction 
					//and there is a direct request to the property_details then it shows empty MHash. 
					
					//removed  the fields through the MasterObj  which is already presents in the MHash  by using removeDuplFromhash method.
					MessageGenerator msg=new MessageGenerator(sqlDB);
					MasterObj=gin.removeDuplFromhash(MHash,MasterObj);	
					Master=msg.convertToMessage(masterTable, process, MasterObj);
					mastermsg=Master;						
					
					presentproperty=msg.convertToMessage(tableName, process, hashobj);
					if(lastMid.equals(Master))
					{							
						presentproperties=presentproperties+presentproperty;
					}
					else
					{
						presentproperties=presentproperties+mastermsg+presentproperty;
					}
					
					lastMid=Master;	
						
				}*/
							
			System.out.println("Request is     "+mastermsg+presentproperties);
			sbrProperty.append(presentproperties);
			
		return new StringBuffer(reponses);
	}
	
	
	public void setPropertyVector(Vector<Object> propertydetails) 
	{
		PropertyList = propertydetails;
	}

	
	@SuppressWarnings("unchecked")
	public String getType() 
	{
		String MasterType;
		MasterType = "null";
		//TYPE=gin.getId(TYPE);
		try 
		{	
			Hashtable<Object,Object> temp = new Hashtable<Object,Object>();
			
			try {
				for(int i=0;i<PropertyList.size();i++)
				{
					temp.clear();
					//Property_details pd = (Property_details)PropertyList.get(i);
					temp.putAll((Hashtable<Object, Object>)  ConvertToLower.convertHashKey((Hashtable<Object, Object>)PropertyList.get(i)));
					String pidvalue = temp.get("pid").toString();
					if(pidvalue.toLowerCase().equals(TYPE))
					{
						MasterType = temp.get("pv").toString();
						break;
					}
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(MasterType.equals("null"))
			{
				String id="";
				for(int i=0;i<OldPropertyVector.size();i++)
				{
					temp.clear();
					//Property_details pd = (Property_details) OldPropertyVector.get(i);
					temp.putAll((Hashtable<Object, Object>) OldPropertyVector.get(i));  
					temp = ConvertToLower.convertHashKey(temp);
					mid=id = temp.get("mid").toString();
					break;
				}
				if(id.length()==0)
				{
					if(MasterMap.containsKey("name"))
					{
						 id =MasterMap.get("name").toString();
						 id = gin.getId(id);
					}	 
					else
						 id =MasterMap.get("id").toString();
				}
				else
					id=mid;
				//String path = Input.MASTERREPORTSPATH + id + "//" + id + "_mid" +Input.FILRFORMAT;
				temp.clear();
				temp.put("pid",TYPE);
				temp.put("mid", id);
				temp.put("td", "null");
				/*file.SearchRecord sr = new SearchRecord(path);
				String line[] =sr.getRecordSet(temp);*/
				
				RecordSearch ps = new RecordSearch(sqlDB);
				ps.setConditionMap(temp);
				String line[] = ps.getArrayFromResultSet();
				for(int i=0;i<line.length;i++)
				{
					String Splitline[]= line[i].split("\t");
					MasterType = Splitline[Column.pv_index-1];
				}
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	  return MasterType; 	
	}


		
	public boolean addMasterToprocessLogger(String mid,String process,String userid,String type, String ProductName)
	{
		 boolean flag = false;
		try 
		{
			//if(PropertyMap.get("pid").toString().equals(TYPE))
			ProcessLogger procLogger = new ProcessLogger(sqlDB);
			procLogger.addLog(mid,"", process, "",userid,ProductName, type);
			flag = true;
			//procLogger.updateLog(mid, "0", request, "5");
			
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}
	

	public Hashtable<Object, Object> getBasicHashtable() {
		return BasicPropertyMap;
	}

	
	
	public void setHashtable(Hashtable<Object, Object> table) 
	{

	}
	
	void setReportMaster(String process)
	{
		 if(type.length()==0)
			 type = getType();
		Hashtable<Object,Object> hasht = new Hashtable<Object, Object>();
		hasht.put("pid", gin.getId("Report"));
		hasht.put("mid", type);
		hasht.put("td", "null");
		RecordSearch rs = new RecordSearch(sqlDB);
		rs.setConditionMap(hasht);
		String line[]=rs.getArrayFromResultSet();
		
		for(int i=0;i<line.length;i++)
		{
			String splitline[] = line[i].split("\t");
			try
			{		
					//INSERTED INTO REPORT_MASTER
				sqlDB.getInsert("insert into report_master(tid, reportOn, process, report_name) values("+mid+", '"+splitline[Column.mid_index-1]+"', '"+"add"+"', '"+gin.getItem(splitline[Column.pv_index-1])+"')");
			}
			catch (Exception e) 
			{
				e.printStackTrace();
			}
		}
	}
	
	
	public StringBuffer getDelete()
	{
		Vector<Object> pdbsVector = new Vector<Object>();
		ChekInMaster check = new ChekInMaster(sqlDB);
		//int flagReport = 0;		

		if(!mid.equals("0"))
		{
			
			System.out.println("You are in pool::PropertyDetails ::getDelete():: ");
			//sbrDTB.append("Properties : ");
			for(int p=0;p<PropertyList.size();p++)
			{
				Hashtable<Object, Object> tempProperty = new Hashtable<Object, Object>();
				tempProperty.putAll((Hashtable<Object, Object>)(PropertyList.get(p)));
				tempProperty.put("mid",mid);
				
				String pattern = "yyyy-MM-dd HH:MM:ss";
				SimpleDateFormat sdm = new SimpleDateFormat(pattern);
				String date = sdm.format(new Date());
				
				tempProperty.put(TODATE, "null");
				Hashtable<Object, Object> oldhash =new Hashtable<Object, Object>();
				oldhash.putAll(tempProperty);
				tempProperty.put(TODATE, date);
				//ps.addMasterToprocessLogger(this.mid, process, username,ty);
				
				
				if(tempProperty.get("pv").equals("0")==true && tempProperty.get("vt").equals("no$")==true)
				{
					String pmid=tempProperty.get("mid").toString();
					String ppid=tempProperty.get("pid").toString();
					oldhash = sqlDB.getSelectCheck("select mid, pid, pv, vt, ref from property_details where mid = '" + pmid + "' and pid = '" + ppid + "'");
				}
				System.out.println("pool::PropertyDetails ::getDelete():: The Property Detail : " + tempProperty);
				System.out.println("pool::PropertyDetails ::getDelete():: The table name : " + tableName);
				Hashtable<Object, Object> tempoldhash = new Hashtable<Object, Object>();
				tempoldhash.putAll(oldhash);
				if(tempoldhash.containsKey("pv"))
				{
					tempoldhash.put("vt", gin.getItem(tempoldhash.get("pv").toString()));
					tempoldhash.remove("pv");
				}	
				Hashtable<Object,Object> oldhashtable =new Hashtable<Object, Object>();
				oldhashtable.putAll(oldhash);
				oldhashtable.put("pv", "0");
				oldhashtable.put("vt", tempoldhash.get("vt").toString());
				if(check.isInProperty_details(oldhash,tableName) == true || check.isInProperty_details(tempoldhash,tableName) == true)
				{
					tempoldhash.put(TODATE, date);
					int i=0;
					i = sqlDB.getUpdate(tableName, tempProperty,oldhash);
					if(i>=0)
						i = sqlDB.getUpdate(tableName, tempoldhash,oldhashtable);
					else
						sqlDB.getUpdate(tableName, tempoldhash,oldhashtable);
					if(i>0)
					{
						eventResult = true;
						pdbsVector.add(tempProperty); // It will create the vector for the Reports class.
						//flagReport = 1;
						System.out.println("\nretail::PropertyDetails ::getDelete():: Deleted Property in " + tableName + " .........\n\n" );
						sbrDTB.append(" Deleted Success fully");			
					}
					else
					{	
						sbrDTB.append("Unable to delete");
						System.out.println("pool::PropertyDetails ::getDelete():: Unable to delete from Property Details\n\n");
					}
				}
				else
				{
					sbrDTB.append("Property doesn't exists ");
					System.out.println("pool::PropertyDetails ::getDelete():: Property doesn't exist ");
				}
			}
			if(eventResult)
			{
				try {
					if(reqParam.getEvent())
					{			
						String type=getType();
						flagResult = addMasterToprocessLogger(this.mid, process, username,type,productName);					 
					}
					else
						flagResult = false;
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		else
		{
			sbrDTB.append("Unable to delete, Because of master entry does not exist...... ");
			System.out.println("pool::PropertyDetails ::getDelete():: Unable to delete from Property Details, Because of master entry does not exist...... ");
		}
		return sbrDTB;
	}

	
	public void setNewPropertyVector(Vector<Object> NewPropertyVector)
	{
		this.NewPropertyVector = NewPropertyVector;	
	}
	
	
	public void setOldPropertyVector(Vector<Object> OldPropertyVector)
	{
		this.OldPropertyVector = OldPropertyVector;	
	}
	
	
	public void setViewHashtable(Hashtable<Object,Object> hashtable) {
		ViewHashtable.putAll(hashtable);
	}
	
	
	public void setId(String mid)
	{
		this.mid = mid;
	}
	
	
	public void setMasterMap(Hashtable<Object, Object> masterHash)
	{
		this.MHash=masterHash;
	}
	

	public void setRequest(String request) 
	{
		Request = request;
	}
	

	public Hashtable<Object, Object> getMasterMap()
	{
		return MHash;		
	}
	
	
	public void setProcess(String tempProcess) 
	{	
		process = tempProcess;
	}
	
	
	/*public StringBuffer getView() 
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		 
		 String masterTable = "master_table"; 
		StringBuffer sbrProperty=new StringBuffer();
		
		Command cp=new Command(message,sqlDB);
		Hashtable<Object, Object> propertyHash= new Hashtable<Object, Object>();	
		propertyHash.putAll(cp.getHashCommand(tableName, message, process));
				if(propertyHash.containsKey("ErrorInput"))
				{
					sbrProperty.append(propertyHash.get("ErrorInput"));
					return sbrProperty;
				}
				propertyHash.putAll(gin.ConvertPVtoVT(propertyHash));
				propertyHash.putAll(gin.getHashMapOfValues(propertyHash));
				propertyHash.putAll(ConvertToLower.convertHashKey(propertyHash));				
				propertyHash.putAll(gin.convertMasterId(propertyHash, tableName, process));
				
		
		String mastermsg="";
							
		
		//propertyHash.putAll(ViewHashtable);
		
				if(propertyHash.get("pv").toString()=="0")
				{
					propertyHash.remove("pv");
				}
				Enumeration< Object> enum1 = propertyHash.keys();
				if(enum1.hasMoreElements()==false)
				{
						sbrProperty.append("Enter condition to view the properties");
						return sbrProperty;
				}
				if(propertyHash.size()==1)
				{
					if(propertyHash.containsKey("pid"))
					{
						sbrProperty.append("plz Enter the value of property ");
						return sbrProperty;					
					}
				}
				
				//According to the propertyHash getSelectVector method checks the condition ,searches all the record
				//through databse or in property_details table and stores into the vrs vector.
				
				Vector<Object> vrs  = new Vector<Object>(); 
					vrs.addAll(sqlDB.getSelectVector(propertyHash, tableName));
			
				String presentproperties="";
				String lastMid="";
				
				//For the wrong input to the trans_property_details request it shows empty records.
				
				if(vrs.isEmpty())
				{
					sbrProperty.append("Record is not avilable");
					return sbrProperty;
				}
				
				for(int i=0;i<vrs.size();i++)
				{
						String presentproperty="";
						String Master=" ";
						Hashtable<Object, Object> hashobj=new Hashtable<Object, Object>();
						Hashtable<Object, Object> MasterObj=new Hashtable<Object, Object>();
						hashobj=(Hashtable<Object, Object>) vrs.get(i);
						hashobj.putAll(ConvertToLower.convertHashKey(hashobj));						
						
						if(hashobj.containsKey("fd"))
						{							
							if(hashobj.get("fd").toString().equals(""))
							{
								hashobj.remove("fd");
							}
						}
						
						if(hashobj.containsKey("td"))
						{
							if(hashobj.get("td").toString().equals(""))
							{
								hashobj.remove("td");
							}
						}
						hashobj.putAll(gin.CheckFromMaster(hashobj,process));
						
						MasterObj.put("name", hashobj.get("mid"));
						MHash=getMasterMap();						
						
						//MHash is set from the master table which contain an name of master only if the request is for  transaction 
						//and there is a direct request to the property_details then it shows empty MHash. 
						
						//removed  the fields through the MasterObj  which is already presents in the MHash  by using removeDuplFromhash method.
						MessageGenerator msg=new MessageGenerator(sqlDB);
						MasterObj=gin.removeDuplFromhash(MHash,MasterObj);	
						Master=msg.convertToMessage(masterTable, process, MasterObj);
						mastermsg=Master;						
						
						presentproperty=msg.convertToMessage(tableName, process, hashobj);
						if(lastMid.equals(Master))
						{							
							presentproperties=presentproperties+presentproperty;
						}
						else
						{
							presentproperties=presentproperties+mastermsg+presentproperty;
						}
						
						lastMid=Master;						
				}
							
				System.out.println("Request is     "+mastermsg+presentproperties);
				sbrProperty.append(presentproperties);
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Property_details","getView",t.duration());
		return sbrProperty;
		
	}*/
	
	/** The getUpdate() will Update the properties into the property_details table.
	 *  @return sbrDTB StringBuffer which store the updation message for the logger class.
	 * */
	/*public StringBuffer getUpdate() 
	{
		ExecutionTimer t = new ExecutionTimer();
		 t.start();
		 
		try 
		{
			if(Request.toLowerCase().equals(tableName))
			{
				//basicprocess.getInsert();
				Hashtable<Object, Object>temperrorhashtable= process();
				if(temperrorhashtable.containsKey("ErrorInput"))
					return new StringBuffer((temperrorhashtable.get("ErrorInput")).toString());
			}	
		}
		catch (Exception e) 
		{
			//e.printStackTrace();
		}
		
		//getMessageValidation();
		directUpdate();		
		t.end();
		@SuppressWarnings("unused")
		TimerRecordFile timerFile=new TimerRecordFile("pool.tablename","Property_details","getUpdate",t.duration());
		return sbrDTB;
	}*/

	/*
	
	public String getTable() 
	{
		return Request;
	}

	*/
	
	/*
	public String getProceess() 
	{
		return process;
	}
	
	

	*/
	public Hashtable<Object, Object> getHashtabel() 
	{
		return MasterMap;
	}

	public Hashtable<Object, Object> getDetailHashtabel() 
	{	
		return new Hashtable<Object, Object>();
	}
	
	public Vector<Object> getpropertyVector() 
	{		
		return PropertyList;
	}
	
	public String getTable() 
	{
		return Request;
	}	
	
	@SuppressWarnings("unchecked")
	private Hashtable<Object, Object> getOldPropertyHash(Hashtable<Object, Object> newPropertyHash) 
	{
		Hashtable<Object, Object> oldHashProperty = new Hashtable<Object, Object>();
		for(int i = 0; i < OldPropertyVector.size(); i++)
		{
			oldHashProperty.putAll((Hashtable<Object, Object> ) OldPropertyVector.get(i));
			
			if(oldHashProperty.get("mid").equals(newPropertyHash.get("mid")))
			{
				if(oldHashProperty.get("pid").equals(newPropertyHash.get("pid")))
				{
					if(!oldHashProperty.containsKey("td"))
						oldHashProperty.put("td", "null");
					if(!oldHashProperty.containsKey("ref"))
						oldHashProperty.put("ref", "null");
					return oldHashProperty;
				}	
			}
		}
		
		oldHashProperty = new Hashtable<Object, Object>();
		oldHashProperty.put("mid", newPropertyHash.get("mid"));
		oldHashProperty.put("pid", newPropertyHash.get("pid"));
		oldHashProperty.put("td", "null");
		return oldHashProperty;		
	}
}

